package com.sgb.link.utils;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.sgb.link.R;
import com.swgk.core.dialog.RoundCornerDialog;

/**
 * @author younghow
 * @date 2020/10/29
 * description：针对与dialog的一些通用设置
 * first:写在前面，我们在命名的时候一定采用驼峰的方式
 * second:在命名的时候一定要做到代码自解释，也就是说我们用翻译就大概知道这个是要干嘛的
 */
public class RoundDialogHelper {

    /**
     * 点击回调
     */
    public interface DialogFunction {
        default void normalRoundDialog() {

        }
    }


    /**
     * 取消、确定按键 都可重新设置文本
     *
     * @param context
     * @param title          标题
     * @param message        信息
     * @param negativeStr    左边键文本
     * @param positiveStr    右边键文本
     * @param dialogFunction 右边键回调
     */
    public static void showDialog(Context context, String title, String message, String negativeStr, String positiveStr, DialogFunction dialogFunction) {
        View view = View.inflate(context, R.layout.dialog_two_btn, null);
        final RoundCornerDialog roundCornerDialog = new RoundCornerDialog(context, 0, 0, view, R.style.RoundCornerDialog);
        roundCornerDialog.show();
        roundCornerDialog.setCanceledOnTouchOutside(false);

        TextView tvTitle = view.findViewById(R.id.tv_title);
        TextView tvMessage = view.findViewById(R.id.tv_message);
        TextView tvLogoutConfirm = view.findViewById(R.id.tv_logout_confirm);
        TextView tvLogoutCancel = view.findViewById(R.id.tv_logout_cancel);
        if (title != null) {
            tvTitle.setVisibility(View.VISIBLE);
            tvTitle.setText(title);
        } else {
            tvTitle.setVisibility(View.GONE);
        }

        if (message != null) {
            tvMessage.setVisibility(View.VISIBLE);
            tvMessage.setText(message);
        } else {
            tvMessage.setVisibility(View.GONE);
        }

        if (negativeStr != null) {
            tvLogoutCancel.setVisibility(View.VISIBLE);
            tvLogoutCancel.setText(negativeStr);
        } else {
            tvLogoutCancel.setVisibility(View.GONE);
        }

        if (positiveStr != null) {
            tvLogoutConfirm.setVisibility(View.VISIBLE);
            tvLogoutConfirm.setText(positiveStr);
        } else {
            tvLogoutConfirm.setVisibility(View.GONE);
        }

        //确定
        tvLogoutConfirm.setOnClickListener(v -> {
            dialogFunction.normalRoundDialog();
            roundCornerDialog.dismiss();
        });

        //取消
        tvLogoutCancel.setOnClickListener(v -> roundCornerDialog.dismiss());
    }

    public static void showSingleDialog(Context context, String title, String message, String postiveText, boolean titleVisiable, int positiveColor, DialogFunction dialogFunction) {
        View view = View.inflate(context, R.layout.library_dialog_one_btn, null);
        final RoundCornerDialog roundCornerDialog = new RoundCornerDialog(context, 0, 0, view, R.style.RoundCornerDialog);
        roundCornerDialog.show();
        roundCornerDialog.setCanceledOnTouchOutside(false);

        TextView tv_title = view.findViewById(R.id.tv_title);
        TextView tv_message = view.findViewById(R.id.tv_message);
        TextView tv_logout_confirm = view.findViewById(R.id.tv_logout_confirm);
        if (titleVisiable) {
            tv_title.setVisibility(View.VISIBLE);
            if (title != null) {
                tv_title.setVisibility(View.VISIBLE);
                tv_title.setText(title);
            } else {
                tv_title.setVisibility(View.GONE);
            }
        } else {
            tv_title.setVisibility(View.GONE);
        }


        if (message != null) {
            tv_message.setVisibility(View.VISIBLE);
            tv_message.setText(message);
        } else {
            tv_message.setVisibility(View.GONE);
        }
        if (postiveText != null) {
            tv_logout_confirm.setText(postiveText);
        }

        if (positiveColor != 0){
            tv_logout_confirm.setTextColor(positiveColor);
        }

        //确定
        tv_logout_confirm.setOnClickListener(v -> {
            dialogFunction.normalRoundDialog();
            roundCornerDialog.dismiss();
        });
    }

}
